package com.zpz.framework.zpzoauth.web;

import com.github.pagehelper.PageInfo;
import com.zpz.framework.zpzoauth.common.result.ZpzOauthResultMsg;
import com.zpz.framework.zpzoauth.common.result.ZpzOauthResultStatus;
import com.zpz.framework.zpzoauth.pojo.vo.DataOauthListVo;
import com.zpz.framework.zpzoauth.pojo.vo.GetDataGroupAccessListVo;
import com.zpz.framework.zpzoauth.service.ZpzOauthDataAccessService;
import com.zpz.framework.zpzoauth.service.ZpzOauthDataGroupService;
import com.zpz.framework.zpzoauth.service.ZpzOauthDataGroupAccessSevice;
import com.zpz.framework.zpzoauth.pojo.qo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

/**
 * @author zhaowen
 * @description 数据权限基本信息管理
 * @create 2019-07-22 11:43
 */
@Api(tags = "数据权限基本信息管理")
@RestController
@RequestMapping(value = "/zpzOauthDatapermissions")
public class ZpzOauthDataAccessController {
    private Logger log = LoggerFactory.getLogger(ZpzOauthDataAccessController.class);
    @Resource
    private ZpzOauthDataAccessService dataOauthAccessService;
    @Resource
    private ZpzOauthDataGroupAccessSevice zpzOauthDataGroupAccessSevice;
    @Resource
    private ZpzOauthDataGroupService dataOauthGroupService;

    @ApiOperation(value = "修改数据权限信息（100040） |负责人：zhangpanzhi",
            notes = "  \n 数据安全：无," +
                    "  \n返回码：0（OK），")
    @ApiImplicitParams({@ApiImplicitParam(name = "modifyFrameDataAccessQo", value = "参数", paramType = "body", dataType = "ModifyFrameDataAccessQo", required = true)})
    @PostMapping(value = "/updateframedataAccess")
    public ZpzOauthResultMsg<Boolean> updateframedataAccess(HttpServletRequest request, @RequestBody ModifyFrameDataAccessQo modifyFrameDataAccessQo) throws Exception{
        return dataOauthAccessService.updateframedataAccess(request,modifyFrameDataAccessQo);
    }

    @ApiOperation(value = "删除数据权限信息（100041） |负责人：zhangpanzhi",
            notes = "  \n 数据安全：无," +
                    "  \n返回码：0（OK），")
    @ApiImplicitParams({@ApiImplicitParam(name = "deleteFrameDataAccessQo", value = "参数", paramType = "body", dataType = "DeleteFrameDataAccessQo", required = true)})
    @PostMapping(value = "/delframedataAccess")
    public ZpzOauthResultMsg<Boolean> delframedataAccess(HttpServletRequest request, @RequestBody DeleteFrameDataAccessQo deleteFrameDataAccessQo) throws Exception{
        return dataOauthAccessService.delframedataAccess(request,deleteFrameDataAccessQo);
    }

    @ApiOperation(value = "查询数据权限列表（接口码：100038） |负责人：张盼枝",
            notes = "  \n 数据安全：无," +
                    "  \n 返回码：0（OK） " +
                    "  \n 1(查询数据为空)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dataOauthListQo",value = "入参",paramType = "body",dataType = "DataOauthListQo",required = false),
    })
    @RequestMapping(value = "/selectDataOauthList",method = RequestMethod.POST)
    public ZpzOauthResultMsg<PageInfo<DataOauthListVo>> selectDataOauthList(HttpServletRequest request, @RequestBody DataOauthListQo dataOauthListQo) throws Exception{
        return dataOauthAccessService.selectDataOauthList(request,dataOauthListQo);
    }

    @ApiOperation(value = "新增数据权限（接口码：100039） |负责人：张盼枝",
            notes = "  \n 数据安全：无," +
                    "  \n 返回码：0（OK）"+
                    "  \n 10023(LICENSE无效，不能为空) " +
                    "  \n 10027(LICENSE中携带了无效的用户编号) " +
                    "  \n 800019(参数校验失败) " +
                    "  \n 31001(该权限编码已存在，请确认) " +
                    "  \n 31000(添加权限失败)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "addDataOauthQo",value = "入参",paramType = "body",dataType = "AddDataOauthQo",required = true),
    })
    @RequestMapping(value = "/insertDataOauth",method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> insertDataOauth(HttpServletRequest request,@RequestBody AddDataOauthQo addDataOauthQo) throws Exception{
        return dataOauthAccessService.insertDataOauth(request,addDataOauthQo);
    }

    @ApiOperation(value = "删除数据权限组(接口码：100037) |负责人：张盼枝",
            notes = "  \n 数据安全：无," +
                    "  \n返回码：0（OK），" +
                    "  \n 10023(LICENSE无效，不能为空) " +
                    "  \n 10027(LICENSE中携带了无效的用户编号) ")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "dataOauthGroupQo",value = "入参",paramType = "body",dataType = "DataOauthGroupQo",required = true),
    })
    @RequestMapping(value = "/deleteDataOauthGroup",method = RequestMethod.POST)
    public ZpzOauthResultMsg<Boolean> deleteDataOauthGroup(HttpServletRequest request, @RequestBody DataOauthGroupQo dataOauthGroupQo) throws Exception{
        return dataOauthGroupService.deleteDataOauthGroup(request,dataOauthGroupQo);
    }

    @ApiOperation(value = "接口：数据权限组分页查询(100034)  负责人：张盼枝",notes = "数据安全：" +
            "返回码：0（OK）")
    @PostMapping("/selectDateGroupAccessList")
    public ZpzOauthResultMsg<PageInfo<GetDataGroupAccessListVo>> selectDateGroupAccessList(@RequestBody GetDataGroupAccessListQo getDataGroupAccessListQo){
        return zpzOauthDataGroupAccessSevice.selectDateGroupAccessList(getDataGroupAccessListQo);
    }


    @ApiOperation(value = "接口：添加数据权限组(100035)  负责人：张盼枝",notes = "数据安全：" +
            "返回码：0（OK）")
    @PostMapping("/insertDateGroupAccess")
    public ZpzOauthResultMsg<Boolean> insertDateGroupAccess(HttpServletRequest request, @RequestBody AddDataGroupQo addDataGroupQo){
        if (StringUtils.isBlank(addDataGroupQo.getGroupName())) {
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.GROUP_NAME_NOT_NULL_31990);
        }

        return zpzOauthDataGroupAccessSevice.insertDateGroupAccess(request,addDataGroupQo);
    }

    @ApiOperation(value = "接口：根据groupCode修改数据权限组值(100036)  负责人：张盼枝",notes = "数据安全：" +
            "返回码：0（OK）")
    @PostMapping("/updateDataGroupByGroupCode")
    public ZpzOauthResultMsg<Boolean> updateDataGroupByGroupCode(HttpServletRequest request,@RequestBody UpdateDataGroupQo updateDataGroupQo){
        if(StringUtils.isBlank(updateDataGroupQo.getGroupCode())){
            return ZpzOauthResultMsg.customResultStatus(ZpzOauthResultStatus.GROUP_CODE_NOT_NULL_31992);
        }
        return zpzOauthDataGroupAccessSevice.updateDataGroupByGroupCode(request,updateDataGroupQo);
    }
}
